<html>
<head><meta charset="utf-8"><title>Extending semantic tokens for functions/macro to parens? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Extending.20semantic.20tokens.20for.20functions.2Fmacro.20to.20parens.3F.html">Extending semantic tokens for functions/macro to parens?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="207648406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Extending%20semantic%20tokens%20for%20functions/macro%20to%20parens%3F/near/207648406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Extending.20semantic.20tokens.20for.20functions.2Fmacro.20to.20parens.3F.html#207648406">(Aug 21 2020 at 15:32)</a>:</h4>
<p>In thinking about ways to improve the usability of highlighted code, I was wondering how useful it would be to extend the semantic tokens for functions and macros to cover the parens that follow them (and add the closing paren).</p>
<p>Nested fn calls, arrays, and curly braces from closures are one of the places where I personally find myself getting tripped up, especially as the compilation error may not be near to where the problem is.</p>
<p>(this idea partially inspired by various "rainbow parenthesis" plugins).</p>



<a name="207659850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Extending%20semantic%20tokens%20for%20functions/macro%20to%20parens%3F/near/207659850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Extending.20semantic.20tokens.20for.20functions.2Fmacro.20to.20parens.3F.html#207659850">(Aug 21 2020 at 17:17)</a>:</h4>
<p>Hm, this sounds interesting, but I'd say that tracking parantheisi structure shoudl probably be sovled by something other than semhi</p>



<a name="207659889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Extending%20semantic%20tokens%20for%20functions/macro%20to%20parens%3F/near/207659889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Extending.20semantic.20tokens.20for.20functions.2Fmacro.20to.20parens.3F.html#207659889">(Aug 21 2020 at 17:17)</a>:</h4>
<p>rainbow parens, breadcrumbs, and  parn guides seem to be an overall better fit here</p>



<a name="207659947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Extending%20semantic%20tokens%20for%20functions/macro%20to%20parens%3F/near/207659947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Extending.20semantic.20tokens.20for.20functions.2Fmacro.20to.20parens.3F.html#207659947">(Aug 21 2020 at 17:18)</a>:</h4>
<p>(as an aside, we already expose paran info via "go to matching brace" request)</p>



<a name="207668597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Extending%20semantic%20tokens%20for%20functions/macro%20to%20parens%3F/near/207668597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Extending.20semantic.20tokens.20for.20functions.2Fmacro.20to.20parens.3F.html#207668597">(Aug 21 2020 at 18:35)</a>:</h4>
<p>I was thinking something less than the full rainbow, where the parens of a fn were included in its semantic highlight.  Which would then allow a pile of closing chars at the end to visually distinguish a bit better:</p>
<p><code>)]}))</code></p>
<p>But there are probably other, better ways to do this.</p>



<a name="207697157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Extending%20semantic%20tokens%20for%20functions/macro%20to%20parens%3F/near/207697157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Extending.20semantic.20tokens.20for.20functions.2Fmacro.20to.20parens.3F.html#207697157">(Aug 21 2020 at 23:53)</a>:</h4>
<p>There's already extensions in various editors that support this behavior. For example: <a href="https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2">https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2</a></p>



<a name="207738519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Extending%20semantic%20tokens%20for%20functions/macro%20to%20parens%3F/near/207738519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Extending.20semantic.20tokens.20for.20functions.2Fmacro.20to.20parens.3F.html#207738519">(Aug 22 2020 at 19:23)</a>:</h4>
<p><span class="user-mention" data-user-id="116114">@Paul Faria</span> -&gt; That's a good point, and probably the right way to go about this.  I'll look into how VSCode deals with multiple extensions applying formatting.</p>
<p>I think, for me, just hitting these would be a huge win:</p>
<ul>
<li>macro bounds</li>
<li>array bounds</li>
<li>closure bounds</li>
</ul>
<p>It's less the nesting of fns, and more the nesting of the various semantic structures (a closure in an array in a macro...):</p>
<div class="codehilite"><pre><span></span><code>let ugly = vec!([34, Foo::Builder({ match bar { Some(thing) =&gt; thing.that, None =&gt; 5 }})]);
</code></pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>